package com.martin.lib_base.ui.screen

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.martin.lib_base.R
import com.martin.lib_base.bean.common.FileBean
import com.martin.lib_base.model.MultipleImagePickModel

@Composable
fun ImageSelector(model: MultipleImagePickModel, columns: Int = 3) {
    VerticalGrid(
        items = model.imageList,
        columns = columns,
        paddingHorizontal = 10.dp,
    ) {
        val bean = it as FileBean
        Box(
            modifier = Modifier.aspectRatio(1f)
        ) {
            if (bean.path.isNullOrEmpty())
                FillSizeImage(model = R.drawable.img_image_picker, modifier = Modifier.clickable {
                    model.pickImage()
                })
            else {
                FillSizeImage(model = bean.path)
                Icon(
                    imageVector = Icons.Default.Delete,
                    contentDescription = null,
                    tint = Color.LightGray,
                    modifier = Modifier
                        .align(Alignment.TopEnd)
                        .padding(5.dp)
                        .size(15.dp)
                        .clickable { model.deleteItem(bean) }
                )
            }
        }
    }

}